package net.apexes.demo.codegen.dslite.qvar.base;

import net.apexes.demo.codegen.entity.base.EntityBase;
import net.apexes.demo.codegen.entity.enums.StatusFlag;
import net.wafo.dslite.core.dsl.ColumnType;
import net.wafo.dslite.core.dsl.SimpleColumn;
import net.wafo.dslite.core.dsl.StringColumn;
import net.wafo.dslite.core.dsl.Table;
import net.wafo.dslite.core.dsl.TemporalColumn;

import java.time.LocalDateTime;

/**
 * @author <a href=mailto:hedyn@foxmail.com>HeDYn</a>
 */
public class QEntityBase<T extends EntityBase> extends Table<T> {

    protected QEntityBase(Class<T> dataClass, String tableName) {
        super(dataClass, tableName);
    }

    public final StringColumn id = varchar("ID", 22).id().build();

    public final SimpleColumn<StatusFlag> statusFlag = simple(StatusFlag.class, ColumnType.VARCHAR, "STATUS_FLAG").width(1).notNull().build();

    public final StringColumn version = varchar("VERSION", 22).notNull().build();

    public final StringColumn crtWho = varchar("CRT_WHO", 22).notNull().build();

    public final TemporalColumn<LocalDateTime> crtTime = datetime("CRT_TIME").notNull().build();

    public final StringColumn updWho = varchar("UPD_WHO", 22).build();

    public final TemporalColumn<LocalDateTime> updTime = datetime("UPD_TIME").build();

    @Override
    public Object getFieldValue(T entity, String fieldName) {
        switch (fieldName) {
            case "id":
                return entity.getId();
            case "statusFlag":
                return entity.getStatusFlag();
            case "version":
                return entity.getVersion();
            case "crtTime":
                return entity.getCrtTime();
            case "crtWho":
                return entity.getCrtWho();
            case "updTime":
                return entity.getUpdTime();
            case "updWho":
                return entity.getUpdWho();
            default:
                return super.getFieldValue(entity, fieldName);
        }
    }

    @Override
    public void setFieldValue(T entity, String fieldName, Object value) {
        switch (fieldName) {
            case "id":
                entity.setId((java.lang.String) value);
                break;
            case "statusFlag":
                entity.setStatusFlag((net.apexes.demo.codegen.entity.enums.StatusFlag) value);
                break;
            case "version":
                entity.setVersion((java.lang.String) value);
                break;
            case "crtTime":
                entity.setCrtTime((java.time.LocalDateTime) value);
                break;
            case "crtWho":
                entity.setCrtWho((java.lang.String) value);
                break;
            case "updTime":
                entity.setUpdTime((java.time.LocalDateTime) value);
                break;
            case "updWho":
                entity.setUpdWho((java.lang.String) value);
                break;
            default:
                super.setFieldValue(entity, fieldName, value);
                break;
        }
    }

}
